package
{
	import events.NavigationEvent;
	import screens.ChooseLevel;
	import screens.ChooseQuestion;
	import screens.ChooseStage;
	import screens.Loading;
	import screens.GamePlay;
	import screens.Menu;
	import screens.Question;
	import screens.UpdateStar;
	import starling.display.Sprite;
	import starling.events.Event;
	
	public class Game extends Sprite
	{
		private var screenLoading:Loading;
		private var ScreenGamePlay:GamePlay;
		private var ScreenUpdateStar : UpdateStar;
		private var ScreenChooseLevel:ChooseLevel;
		private var screenMenu:Menu;
		private var ScreenChooseStage:ChooseStage;
		private var ScreenTest:Question;
		private var ScreenChooseQuestion:ChooseQuestion;
		public function Game()
		{
			super();
			this.addEventListener(starling.events.Event.ADDED_TO_STAGE, onAddedToStage);
			this.addEventListener(starling.events.Event.ENTER_FRAME, update);
		}
		
		private function update(e:Event):void 
		{
			if (screenLoading.m_loadComplete == true)
			{
				this.removeEventListener(starling.events.Event.ENTER_FRAME, update);
				screenLoading.m_next = true;
				
				ScreenUpdateStar = new UpdateStar();
				ScreenChooseLevel = new ChooseLevel();
				ScreenChooseStage = new ChooseStage();
				ScreenChooseQuestion = new ChooseQuestion();
				screenMenu = new Menu();
				ScreenTest = new Question();

				//ScreenGamePlay = new GamePlay();
				//ScreenGamePlay.disposeTemporarily();
				ScreenChooseLevel.disposeTemporarily();
				ScreenChooseStage.disposeTemporarily();
				ScreenTest.disposeTemporarily();
				ScreenChooseQuestion.disposeTemporarily();
				screenMenu.disposeTemporarily();
				ScreenUpdateStar.disposeTemporarily();
				
				this.addChild(screenMenu);	
				this.addChild(ScreenChooseLevel);
				this.addChild(ScreenChooseStage);
				//this.addChild(ScreenGamePlay);
				this.addChild(ScreenTest);
				this.addChild(ScreenChooseQuestion);
				this.addChild(ScreenUpdateStar);
				
				//ScreenChooseLevel.m_testInit = true;
				//ScreenGamePlay.m_testInit = true;
				//ScreenUpdateStar.m_testInit = true;
				//ScreenTest.m_testInit = true;
				//ScreenChooseQuestion.m_testInit = true;
			}
		}
		
		private function onAddedToStage(event:Event):void
		{
			trace("starling framework initialized!");
			
			this.addEventListener(NavigationEvent.CHANGE_SCREEN, onChangeScreen);
			screenLoading = new Loading();
			this.addChild(screenLoading);
			
			
			
		}
		private function onChangeScreen(event:NavigationEvent):void 
		{
			switch(event.params.id)
			{
				case "menu":
					screenLoading.disposeTemporarily();
					
					//ScreenUpdateStar.visible = true;
					//ScreenGamePlay.visible = true;
					screenMenu.m_testInit = true;
					screenMenu.visible = true;
					screenMenu.m_testStart = true;
					//ScreenChooseLevel.visible = true;
					break;
				case "ChooseLevel-GamePlay":
					ScreenChooseLevel.disposeTemporarily();
					ScreenGamePlay = new GamePlay();
					this.addChild(ScreenGamePlay);
					ScreenGamePlay.m_testInit = true;
					ScreenGamePlay.visible = true;
					ScreenGamePlay.m_testStart = true;
					ScreenGamePlay.m_testplaybutton = false;
					ScreenGamePlay.width = 1050;
					ScreenGamePlay.width = 700;
					ScreenGamePlay.pivotX = 1050 / 2;
					ScreenGamePlay.pivotY = 700 / 2;
					ScreenGamePlay.x = 1050 / 2;
					ScreenGamePlay.y = 700 / 2;
					break;
				case "ChooseStage-ChooseLevel":
					ScreenChooseStage.disposeTemporarily();
					ScreenChooseLevel.visible = true;
					ScreenChooseLevel.m_testStart = true;
					ScreenChooseLevel.m_testInit=true;
					break;
				case "ChooseStage-Menu":
					ScreenChooseStage.disposeTemporarily();
					screenMenu.m_testInit = true;
					screenMenu.visible = true;
					screenMenu.m_testStart = true;
					break;
				case "ChooseLevel-ChooseStage":
					ScreenChooseLevel.disposeTemporarily();
					ScreenChooseStage.visible = true;
					ScreenChooseStage.m_testStart = true;
					ScreenChooseStage.m_testInit = true;
					break;
				case "Menu-ChooseStage":
					screenMenu.disposeTemporarily();
					ScreenChooseStage.visible = true;
					ScreenChooseStage.m_testStart = true;
					ScreenChooseStage.m_testInit = true;
					break;
				case "Menu-ChooseQuestion":
					screenMenu.disposeTemporarily();
					ScreenChooseQuestion.visible = true;
					ScreenChooseQuestion.m_testStart = true;
					ScreenChooseQuestion.m_testInit = true;
					break;
				case "ChooseQuestion-Test":
					ScreenChooseQuestion.disposeTemporarily();
					ScreenTest.visible = true;
					ScreenTest.m_testStart = true;
					ScreenTest.m_testInit = true;
					break;
				case "ChooseQuestion-Menu":
					ScreenChooseQuestion.disposeTemporarily();
					screenMenu.m_testInit = true;
					screenMenu.visible = true;
					screenMenu.m_testStart = true;
					break;
				case "Test-Test":
					ScreenTest.disposeTemporarily();
					ScreenTest.visible = true;
					ScreenTest.m_testStart = true;
					ScreenTest.m_testInit = true;
					break;
				case "Test-ChooseQuestion":
					ScreenTest.disposeTemporarily();
					ScreenChooseQuestion.visible = true;
					ScreenChooseQuestion.m_testStart = true;
					ScreenChooseQuestion.m_testInit = true;
					break;
				case "GamePlay-ChooseLevel":
					ScreenGamePlay.release();
					ScreenGamePlay.disposeTemporarily();
					this.removeChild(ScreenGamePlay, false);
					ScreenChooseLevel.visible = true;
					ScreenChooseLevel.m_testStart = true;
					ScreenChooseLevel.m_testInit = true;
					break;
				case "GamePlay-GamePlay":
					ScreenGamePlay.release();
					ScreenGamePlay.disposeTemporarily();
					this.removeChild(ScreenGamePlay, false);
					ScreenGamePlay = new GamePlay();
					this.addChild(ScreenGamePlay);
					ScreenGamePlay.m_testInit = true;
					ScreenGamePlay.visible = true;
					ScreenGamePlay.m_testStart = true;
					ScreenGamePlay.m_testplaybutton = false;
					ScreenGamePlay.width = 1050;
					ScreenGamePlay.width = 700;
					ScreenGamePlay.pivotX = 1050 / 2;
					ScreenGamePlay.pivotY = 700 / 2;
					ScreenGamePlay.x = 1050 / 2;
					ScreenGamePlay.y = 700 / 2;
					break;
				case "ChooseLevel-UpdateStar":
					ScreenChooseLevel.disposeTemporarily();
					ScreenUpdateStar.m_testInit = true;
					ScreenUpdateStar.visible = true;
					ScreenUpdateStar.m_testStart = true;
					break;
				case "UpdateStar-ChooseLevel":
					ScreenUpdateStar.disposeTemporarily();
					ScreenChooseLevel.m_testInit = true;
					ScreenChooseLevel.visible = true;
					ScreenChooseLevel.m_testStart = true;
					break;
			}
		}
	}
}